package com.cyt.web.controller.work.wb.wbbulid;

import com.cyt.base.enums.BusinessType;
import com.cyt.base.enums.OperatorType;
import com.cyt.base.model.dto.ReturnResult;
import com.cyt.sys.aspect.BaseLog;
import com.cyt.web.controller.base.BaseController;
import com.cyt.work.wb.model.po.WxWbBulid;
import com.cyt.work.wb.model.vo.WxWbBulidVo;
import com.cyt.work.wb.service.WxWbBulidService;
import com.github.pagehelper.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 维保模块-建筑物表控制层
 *
 * @author ding xu
 * @date 2019-11-25 8:51:24
 */
@RestController
public class WxWbBulidController extends BaseController {

    @Resource
    private WxWbBulidService wxWbBulidService;

    /**
     * 统一跳转
     *
     * @param pageName 页面名称
     * @param applyId 应用id
     * @return ModelAndView
     * @author shengQiang Yu
     * @date 2019-08-28 15:17:40
     */
    @RequestMapping("/work/wb/{pageName}")
    public ModelAndView goPage(@PathVariable("pageName") String pageName, String applyId) {
        ModelAndView view = new ModelAndView("/work/wb/"+pageName);
        view.addObject("applyId", applyId);
        return view;
    }

    /**
     * 分页查询
     *
     * @param wxWbBulidVo 接受参数对象
     * @param page 分页数
     * @param limit 每页显示条数
     * @return ReturnResult
     * @author ding xu
     * @date 2019-11-25 8:51:24
     */
    @BaseLog(module = "维保模块", classz = "建筑物表", methods = "分页查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wb/wxwbbulid/findPage", method = RequestMethod.POST)
    public ReturnResult findPage(WxWbBulidVo wxWbBulidVo, int page, int limit) {
        return wxWbBulidService.findPage(wxWbBulidVo, page, limit);
    }



    /**
     * 分页查询
     *
     * @param wxWbBulidVo 接受参数对象
     * @param page 分页数
     * @param limit 每页显示条数
     * @return ReturnResult
     * @author ding xu
     * @date 2019-11-25 8:51:24
     */
    @BaseLog(module = "维保模块", classz = "建筑物表", methods = "分页查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wb/wxwbbulid/findVoPage", method = RequestMethod.POST)
    public ReturnResult findVoPage(WxWbBulidVo wxWbBulidVo, int page, int limit) {
        return wxWbBulidService.findVoPage(wxWbBulidVo, page, limit);
    }

    /**
     * list查询
     *
     * @param wxWbBulidVo 接受参数对象
     * @return ReturnResult
     * @author ding xu
     * @date 2019-11-25 8:51:24
     */
    @BaseLog(module = "维保模块", classz = "建筑物表", methods = "list查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wb/wxwbbulid/findList", method = RequestMethod.POST)
    public ReturnResult findList(WxWbBulidVo wxWbBulidVo) {
        return new ReturnResult(wxWbBulidService.findList(wxWbBulidVo));
    }

    /**
     * list查询
     *
     * @param wxWbBulidVo 接受参数对象
     * @return ReturnResult
     * @author ding xu
     * @date 2019-11-25 8:51:24
     */
    @BaseLog(module = "维保模块", classz = "建筑物表", methods = "list查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wb/wxwbbulid/findVoList", method = RequestMethod.POST)
    public ReturnResult findVoList(WxWbBulidVo wxWbBulidVo) {
        return new ReturnResult(wxWbBulidService.findVoList(wxWbBulidVo));
    }

    /**
     * 单个对象查询
     *
     * @param wxWbBulidVo 接受参数对象
     * @return ReturnResult
     * @author ding xu
     * @date 2019-11-25 8:51:24
     */
    @BaseLog(module = "维保模块", classz = "建筑物表", methods = "one查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wb/wxwbbulid/findOne", method = RequestMethod.POST)
    public ReturnResult findOne(WxWbBulidVo wxWbBulidVo) {
        return new ReturnResult(wxWbBulidService.findOne(wxWbBulidVo));
    }

    /**
     * 单个对象查询
     *
     * @param wxWbBulidVo 接受参数对象
     * @return ReturnResult
     * @author ding xu
     * @date 2019-11-25 8:51:24
     */
    @BaseLog(module = "维保模块", classz = "建筑物表", methods = "one查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wb/wxwbbulid/findVoOne", method = RequestMethod.POST)
    public ReturnResult findVoOne(WxWbBulidVo wxWbBulidVo) {
        return new ReturnResult(wxWbBulidService.findVoOne(wxWbBulidVo));
    }

    /**
     * 跳转添加或编辑界面
     *
     * @param id 主键
     * @param parentId 父节点id
     * @return ReturnResult
     * @author ding xu
     * @date 2019-11-25 8:51:24
     */
    @BaseLog(module = "维保模块", classz = "建筑物表", methods = "跳转添加或编辑界面", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wb/wxwbbulid/getEdit", method = RequestMethod.GET)
    public ModelAndView getEdit(String id, String parentId) {
        ModelAndView view = new ModelAndView("/work/wb/wbbulidadd");
        if (id != null && !"".equals(id)) {
            WxWbBulid wxWbBulid = wxWbBulidService.selectByPrimaryKey(id);
            view.addObject(wxWbBulid);
        }
        if (StringUtil.isNotEmpty(parentId)) {
            WxWbBulid wxWbBulid = new WxWbBulid();
            wxWbBulid.setParentId(parentId);
            view.addObject(wxWbBulid);
        }

        return view;
    }

    /**
     * @param id 主键
     * @param parentId 父节点id
     * @author: dingxu
     * @date: 2019-11-25 8:51:24
     * @Description: 添加页面跳转
     */
    @RequestMapping(value = "/wb/wxwbbulid/getAdd", method = RequestMethod.GET)
    public ModelAndView getAdd(String id, String parentId,String applyId) {
        ModelAndView view = new ModelAndView("/work/wb/wbbulidadd");
        WxWbBulid wxWbBulid= new WxWbBulid();
        if (id != null && !"".equals(id)) {
            wxWbBulid = wxWbBulidService.selectByPrimaryKey(id);
            if(StringUtils.isNotBlank(wxWbBulid.getParentId())){
                WxWbBulid wxWbBulidp = wxWbBulidService.selectByPrimaryKey(wxWbBulid.getParentId());
                wxWbBulid.setParentName(wxWbBulidp.getName());
            }
        }
        if (StringUtil.isNotEmpty(parentId)) {
            WxWbBulid wxWbBulidp = wxWbBulidService.selectByPrimaryKey(parentId);
            wxWbBulid.setParentName(wxWbBulidp.getName());
            wxWbBulid.setParentId(parentId);
        }
        wxWbBulid.setApplyId(applyId);
        view.addObject(wxWbBulid);
        return view;
    }

    /**
     * 保存或更新
     *
     * @param request 请求对象
     * @param wxWbBulidVo 接受参数对象
     * @return ReturnResult
     * @author ding xu
     * @date 2019-11-25 8:51:24
     */
    @BaseLog(module = "维保模块", classz = "建筑物表", methods = "保存或更新对象", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wb/wxwbbulid/addOrUpdate", method = RequestMethod.POST)
    public ReturnResult addOrUpdate(HttpServletRequest request, WxWbBulidVo wxWbBulidVo) {
        return wxWbBulidService.addOrUpdate(wxWbBulidVo, acceptCurrentUser(request));
    }

    /**
     * 根据条件逻辑删除
     *
     * @param request 请求对象
     * @param wxWbBulidVo 接受参数对象
     * @return ReturnResult
     * @author ding xu
     * @date 2019-11-25 8:51:24
     */
    @BaseLog(module = "维保模块", classz = "建筑物表", methods = "逻辑删除对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wb/wxwbbulid/remove", method = RequestMethod.GET)
    public ReturnResult remove(HttpServletRequest request, WxWbBulidVo wxWbBulidVo) {
        return wxWbBulidService.remove(wxWbBulidVo, acceptCurrentUser(request));
    }

    /**
     * 根据条件物理删除
     *
     * @param request 请求对象
     * @param wxWbBulidVo 接受参数对象
     * @return ReturnResult
     * @author ding xu
     * @date 2019-11-25 8:51:24
     */
    @BaseLog(module = "维保模块", classz = "建筑物表", methods = "物理对象对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wb/wxwbbulid/delete", method = RequestMethod.GET)
    public ReturnResult delete(HttpServletRequest request, WxWbBulidVo wxWbBulidVo) {
        return wxWbBulidService.delete(wxWbBulidVo, acceptCurrentUser(request));
    }

    /**
     * 获取菜单树
     *
     * @param wxWbBulidVo 接受参数对象
     * @return ReturnResult
     * @author ding xu
     * @date 2019-11-25 8:51:24
     */
    @BaseLog(module = "维保模块", classz = "场地树状图", methods = "菜单树", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wb/wxwbbulid/dTreeList", method = RequestMethod.POST)
    public ReturnResult dTreeList(WxWbBulidVo wxWbBulidVo) {
        return wxWbBulidService.dTreeList(wxWbBulidVo);
    }

    /**
     * 获取菜单树（用于房间管理）
     *
     * @param wxWbBulidVo 接受参数对象
     * @return ReturnResult
     * @author ding xu
     * @date 2019-11-25 8:51:24
     */
    @BaseLog(module = "维保模块", classz = "场地树状图", methods = "菜单树", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wb/wxwbbulid/dTreeListRoom", method = RequestMethod.POST)
    public ReturnResult dTreeListRoom(WxWbBulidVo wxWbBulidVo) {
        return wxWbBulidService.dTreeListRoom(wxWbBulidVo);
    }
    /**
     * 获取菜单树（建筑+房间）
     *
     * @param wxWbBulidVo 接受参数对象
     * @return ReturnResult
     * @author ding xu
     * @date 2019-11-25 8:51:24
     */
    @BaseLog(module = "维保模块", classz = "场地树状图", methods = "菜单树", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wb/wxwbbulid/dTreeListBulidAndRoom", method = RequestMethod.POST)
    public ReturnResult dTreeListBulidAndRoom(WxWbBulidVo wxWbBulidVo) {
        return wxWbBulidService.dTreeListBulidAndRoom(wxWbBulidVo);
    }
}